#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QHBoxLayout>
#include <QSqlTableModel>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //载入数据库
    ui->widget->loadDB("testDB.db");

    //为数据库添加表
    QString tab1 = QString("CREATE TABLE IF NOT EXISTS tab1(\
                                  ID integer primary key autoincrement, \
                                  UserName TEXT, \
                                  Password TEXT, \
                                  DateTime TEXT  )");
    ui->widget->creatTab(tab1);
    qDebug()<<ui->widget->getHeaderList("tab1");

    QString tab2 = QString("CREATE TABLE IF NOT EXISTS tab2(\
                                  ID integer primary key autoincrement, \
                                  UserName TEXT, \
                                  Password TEXT, \
                                  iLevel integer, \
                                  strLevel TEXT, \
                                  Department TEXT, \
                                  DateTime TEXT  )");
    ui->widget->creatTab(tab2);
    qDebug()<<ui->widget->getHeaderList("tab2");

    //获取显示数据库所有表
    QStringList tabList = ui->widget->getTabNames();
    ui->comboBox->addItems(tabList);

    ui->widget->setMoveEnable(1);
    ui->widget->move(10,10);
    ui->widget->resize(400,800);
    ui->widget->show();

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_comboBox_currentIndexChanged(const QString &arg1)   //切换数据库表
{
    ui->widget->setShowModel(arg1);
}

void MainWindow::on_pushButton_inset_clicked()  //插入、添加
{

}
void MainWindow::on_pushButton_delete_clicked() //删除
{

}
void MainWindow::on_pushButton_queue_clicked()  //查找
{

}
void MainWindow::on_pushButton_edit_clicked()   //编辑
{

}

void MainWindow::on_comboBox_2_currentIndexChanged(int index)   //修改表格显示风格
{

}

void MainWindow::on_checkBox_move_clicked()
{

}
